package com.HQCourse.emple;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class demo {
    public static void main(String[] args) {
        DatagramSocket datagramSocket=null;
        try {
            datagramSocket=new DatagramSocket(8001);
            byte[] bytes=new byte[1024];
            DatagramPacket datagramPacket=new DatagramPacket(bytes,bytes.length);
            System.out.println("8001监听中");
            datagramSocket.receive(datagramPacket);
            int len=datagramPacket.getLength();
            byte[] data=datagramPacket.getData();
            String s = new String(data, 0, len);
            System.out.println(s);
        } catch (SocketException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
